import request from "@/utils/request";

// 指定请求头格式
const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

// 请求头添加 Autrization: Basic client_id: client_secret
const auth = {
    username: 'jili20-admin',
    password: '123456'
}

// 登录
export function login(data) {
    return request({
        headers,
        auth,
        url: `/auth/login`,
        method: 'post',
        params: data
    })
}

// 访问协议
export function getXieyi() {
    return request({
        url: `${window.location.protocol}//${window.location.host}/xieyi.html`,
        method: 'get'
    })
}

// 查询用户名是否已经被注册
export function getUserByUsername(username) {
    return request({
        url: `/system/api/user/username/${username}`,
        method: 'get',
    })
}

// 查询手机号是否已经被注册
export function getPhoneVerificationCode(phone) {
    return request({
        url: `/party/api/sms/send/${phone}`,
        method: 'get',
    })
}


// 注册接口
export function register(data) {
    return request({
        url: `/system/api/user/register`,
        method: 'post',
        data
    })
}

// 退出登录
export function logout(accessToken) {
    return request({
        url: `/auth/logout`,
        method: 'get',
        params: {
            accessToken
        }
    })
}

// 刷新令牌获取新的认证信息
export function refreshToken(refreshToken) {
    return request({
        headers,
        auth,
        url: '/auth/user/refreshToken',
        method: 'get',
        params: {
            refreshToken
        }
    })
}


// 找回密码-查询手机号是否未被注册(用户修改密码用)
export function checkPhoneVerificationCode(phone) {
    return request({
        url: `/party/api/sms/send/update/password/${phone}`,
        method: 'get',
    })
}

// 找回密码
export function findUserPassword(data) {
    return request({
        url: `/system/api/user/find/password`,
        method: 'put',
        data
    })
}
